/// 厦门大学计算机专业 | 华为开发专家(HDE)
/// 专注《零基础学编程系列》  http://lblbc.cn/blog
/// 包含：鸿蒙 | Java | 安卓 | 前端 | Flutter | iOS | 小程序
/// 公众号：蓝不蓝编程
import 'dart:math';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: '选号工具'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String num1 = "0";
  String num2 = "0";
  String num3 = "0";
  String num4 = "0";
  String num5 = "0";
  String num6 = "0";
  String num7 = "0";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                buildNumView(num1),
                buildNumView(num2),
                buildNumView(num3),
                buildNumView(num4),
                buildNumView(num5),
                buildNumView(num6),
                buildNumView(num7),
              ],
            ),
            const SizedBox(height: 20),
            ElevatedButton(
                onPressed: createNums,
                style: ElevatedButton.styleFrom(
                    backgroundColor: Colors.blue,
                    foregroundColor: Colors.white),
                child: const Text("生成"))
          ],
        ),
      ),
      // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

  createNums() {
    setState(() {
      num1 = random(33).toString();
      num2 = random(33).toString();
      num3 = random(33).toString();
      num4 = random(33).toString();
      num5 = random(33).toString();
      num6 = random(33).toString();
      num7 = random(16).toString();
    });
  }

  random(int maxNum) {
    return Random().nextInt(maxNum) + 1;
  }

  buildNumView(String num) {
    return Container(
        decoration: BoxDecoration(
            border: Border.all(color: Colors.grey, width: 1),
            borderRadius: BorderRadius.circular(20)),
        width: 40,
        height: 40,
        child: Center(child: Text(num)));
  }
}
